package Hash;

import java.util.ArrayList;
import java.util.Arrays;

public class IsPalindrome18 {
    public static void main(String[] args) {
        System.out.println(isPalindrome("A man, a plan, a canal: Panama"));

    }
    public static boolean isPalindrome(String s) {
        if(s == null){
            return true;
        }
        String s1 = s.toLowerCase();
//        System.out.println(s1);
//        char[] chars = s1.toCharArray();
        int i = 0,j = s1.length()-1;
        while(i<j){
            while(i < j  && !Character.isLetterOrDigit(s1.charAt(i))){
                i++;
            }
            while(i < j  && !Character.isLetterOrDigit(s1.charAt(j))){
                j--;
            }
            if(i < j){
                if(s1.charAt(i) != s1.charAt(j)){
                    return false;
                }
                i++;
                j--;
            }
        }
        return true;



    }
}
